import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import TableControls from '#cpt/temp/TableControls'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
import AddEditModal from '#cpt/temp/AddEditModal'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Box = $Lazy.load(()=>import('#tp/box/box'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		formData : [
			{ label: '结果代码',				name: 'result_code',		full:true, 	required:true,},
			{ label: '结果内容',				name: 'result_content',		full:true, 	required:true, type:'textarea' },
			{ label: '结果内容(英文)',		name: 'en_result_content',	full:true, 	required:true, type:'textarea' },
			{ label: '是否默认',				name: 'is_default',			full:true, 	type:'switch' },
		]
	}
	
	model = {}
	
	componentDidMount(){
		const { kind_id } = this.props
		this.model = this.submit = { kind_id }
		this.fetch()
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'report-result-info/index')
	
	// 表单
	cols = [
		{ title: '是否默认',			dataIndex: 'is_default', 			...$fn.table.isDefault },
		{ title: '结果内容', 		dataIndex: 'result_content', 		width:200 },
		{ title: '结果内容(英文)', 	dataIndex: 'en_result_content', 	width:200},
		{ title: '结果代码', 		dataIndex: 'result_code', 			width:200},
		TableControls.controls.call(this,{ width: 80 })
	]
	// 表格操作按钮
	table_controls = (text,{ uuid }) => {
		return [
			TableControls.edit.call(this,'report-result-info/info', { uuid }, { disabled:this.props.disabled }),
		]
	}
	// 操作按钮
	controls = () => {
		const { disabled } = this.props
		return [
			Controls.add.call(this,{code:false, disabled}),
			Confirm.call(this,'删除', 'report-result-info/del', { isKeys: true, ghost:true, disabled })
		]
	}
	render(){
		const title = '报告结果字典'
		const { className, disabled } = this.props
		return (
			<>
				<Box key={disabled} title={title} controls={this.controls()} className={className ? className: 'mt5'} contentClassName='pt10'>
					{/* 表格 */}
					{ Table.call(this, { wrapStyle: this.props.tableStyle, disabled }) }
				</Box>
				{/* 添加、编辑 */}
				{ AddEditModal.call(this,{ title, labelWidth:'s8', api: 'report-result-info/add', editApi: 'report-result-info/edit' }) }
			</>
		)
	}
}

export default Index